package com.example.demo.jdk.collection;

import java.util.Objects;
import java.util.function.Predicate;

/**
 * @author: htc
 * @date: Created in 10:46 2018/11/26.
 */
public interface MyCollection<E> extends MyIterator<E> {

    int size();

    boolean isEmpty();

    boolean contains(Object o);

    MyIterator<E> iterator();

    Object[] toArray();

    <T> T[] toArray(T[] a);

    boolean add(E e);

    boolean remove(Object o);

    boolean containsAll(MyCollection<?> c);

    boolean addAll(MyCollection<? extends E> c);

    boolean removeAll(MyCollection<?> c);

    default boolean removeIf(Predicate<? super E> filter) {
        Objects.requireNonNull(filter);
        boolean removed = false;
        final MyIterator<E> each = iterator();
        while (each.hasNext()) {
            if (filter.test(each.next())) {
                each.remove();
                removed = true;
            }
        }
        return removed;
    }

    boolean retainAll(MyCollection<?> c);

    void clear();

}
